home *** CD-ROM | disk | FTP | other *** search
/ Total Network Tools 2002 / NextStepPublishing-TotalNetworkTools2002-Win95.iso / Archive / Web Server / PHP.EXE / pear / PHPDoc / xmlexporter / PhpdocXMLClassExporter.php next >
Encoding:
PHP Script  |  2001-02-18  |  6.2 KB  |  183 lines

  1. <?php
  2. /**
  3. * Exports the data of a class as an xml file.
  4. *
  5. * @version  $Id: PhpdocXMLClassExporter.php,v 1.3 2001/02/18 16:53:00 uw Exp $
  6. */
  7. class PhpdocXMLClassExporter extends PhpdocXMLDocumentExporter {
  8.  
  9.     /**
  10.     * Variable container attributes.
  11.     *
  12.     * @var  array   $variableAttributes
  13.     */                                                        
  14.     var $variableAttributes = array(
  15.                                     "name"      => "CDATA",
  16.                                     "access"    => "CDATA",
  17.                                     "type"      => "CDATA",
  18.                                     "abstract"  => "Boolean",
  19.                                     "static"    => "Boolean",
  20.                                     "final"     => "Boolean"
  21.                                 );        
  22.     /**
  23.     * Class container attributes.
  24.     *
  25.     * @var  array   $classAttributes
  26.     */
  27.     var $classAttributes = array(     
  28.                                 "name"      => "CDATA",
  29.                                 "extends"   => "CDATA",
  30.                                 "undoc"     => "Boolean",
  31.                                 "access"    => "CDATA",
  32.                                 "abstract"  => "Boolean",
  33.                                 "static"    => "Boolean",
  34.                                 "final"     => "Boolean",
  35.                                 "package"   => "CDATA"
  36.                             );
  37.  
  38.     var $fileprefix = "class_";
  39.     
  40.     function PhpdocXMLClassExporter() {
  41.         $this->PHPDocXMLExporter();
  42.     } // end constructor
  43.     
  44.     function create() {
  45.         
  46.         $attribs = $this->getAttributes($this->result, $this->classAttributes);                                        
  47.         $this->xmlwriter->startElement("class", "", $attribs, false);
  48.         
  49.         $this->filenameXML($this->result["filename"]);
  50.         
  51.         $this->docXML($this->result);    
  52.         
  53.         if (isset($this->result["functions"]))
  54.             $this->functionsXML($this->result["functions"]);
  55.             
  56.         if (isset($this->result["variables"]))
  57.             $this->variablesXML($this->result["variables"]);
  58.             
  59.         if (isset($this->result["uses"]))
  60.             $this->usesXML($this->result["uses"]);
  61.             
  62.         if (isset($this->result["consts"]))
  63.             $this->constsXML($this->result["consts"]);
  64.             
  65.         if (isset($this->result["inherited"]))
  66.             $this->inheritedOverridenXML($this->result["inherited"], "inherited");
  67.             
  68.         if (isset($this->result["overriden"]))
  69.             $this->inheritedOverridenXML($this->result["overriden"], "overriden");
  70.             
  71.         if (isset($this->result["path"]))
  72.             $this->pathXML($this->result["path"]);
  73.         
  74.         if (isset($this->result["baseclass"]))
  75.             $this->baseclassXML($this->result["baseclass"]);
  76.         
  77.         if (isset($this->result["subclasses"]))
  78.             $this->subclassesXML($this->result["subclasses"]);
  79.             
  80.         $this->xmlwriter->endElement("class", true);
  81.         
  82.     } // end func create
  83.     
  84.     /**
  85.     * Handles inherited and overriden elements.
  86.     * 
  87.     * @param    array   Array of inherited or overriden elements
  88.     * @param    string  Container used when saving the elements
  89.     */
  90.     function inheritedOverridenXML($data, $tag) {
  91.         
  92.         reset($data);
  93.         while (list($type, $elements) = each($data)) {
  94.         
  95.             reset($elements);
  96.             while (list($from, $data2) = each($elements)) {
  97.  
  98.                 $attribs = $this->getAttributes( array ("type" => $type, "src" => $from), $this->inheritedOverridenAttributes);                
  99.                 $this->xmlwriter->startElement($tag, "", $attribs, false);
  100.                 
  101.                 reset($data2);
  102.                 while (list($name, $v) = each($data2))
  103.                     $this->xmlwriter->addElement("element", $name);
  104.                     
  105.                 $this->xmlwriter->endElement($tag, true);
  106.                     
  107.             }
  108.             
  109.         }
  110.         
  111.     } // end func inheritedOverridenXML
  112.  
  113.     /**
  114.     * Writes the "path" (inheritance chain) of an element.
  115.     *
  116.     * @param    array
  117.     */    
  118.     function pathXML($path) {
  119.         if (0 == count($path))
  120.             return;
  121.             
  122.         $this->xmlwriter->startElement("path", "", "", false);            
  123.         
  124.         reset($path);
  125.         while (list($k, $parent) = each($path)) 
  126.             $this->xmlwriter->addElement("parent", $parent);
  127.         
  128.         $this->xmlwriter->endElement("path", true);
  129.         
  130.     } // end func pathXML
  131.     
  132.     /**
  133.     * Adds a baseclass container to the generated xml.
  134.     *
  135.     * @param    string  Name of the baseclass
  136.     */
  137.     function baseclassXML($base) {
  138.     
  139.         if ("" != $base)
  140.             $this->xmlwriter->addElement("baseclass", $base);
  141.             
  142.     } // end func baseclassXML
  143.     
  144.     /**
  145.     * Adds a list of subclasses to the generated xml.
  146.     *
  147.     * @param    array    
  148.     */
  149.     function subclassesXML($subclasses) {
  150.         if (0 == count($subclasses))
  151.             return;
  152.         
  153.         $this->xmlwriter->startElement("subclasses", "", "", false, true);    
  154.         
  155.         reset($subclasses);
  156.         while(list($subclass, $v) = each($subclasses)) 
  157.             $this->xmlwriter->addElement("subclass", $subclass);
  158.         
  159.         $this->xmlwriter->endElement("subclasses", true);
  160.         
  161.     } // end func subclassesXML
  162.     
  163.     /**
  164.     * Adds class variables to the XMl document.
  165.     *
  166.     * @param    array
  167.     */
  168.     function variablesXML($variables) {
  169.                                                             
  170.         reset($variables);
  171.         while (list($variable, $data) = each($variables)) {
  172.         
  173.             $attribs = $this->getAttributes($data, $this->variableAttributes);
  174.             $this->xmlwriter->startElement("variable", $data["value"], $attribs, false);
  175.             $this->docXML($data);
  176.             $this->xmlwriter->endElement("variable", true);
  177.             
  178.         }
  179.         
  180.     } // end func variablesXML
  181.     
  182. } // end class PhpdocXMLClassExporter
  183. ?>